package com.java110.mall.market.bmo.room.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.user.UserAttrDto;
import com.java110.intf.user.IUserV1InnerServiceSMO;
import com.java110.mall.market.bmo.room.IGetRoomsByUserBMO;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("getRoomsByUserBMOImpl")
public class GetRoomsByUserBMOImpl implements IGetRoomsByUserBMO {



    @Autowired
    private IUserV1InnerServiceSMO userInnerServiceSMOImpl;

//    @Autowired
//    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;

    @Override
    public ResponseEntity<String> getRooms(JSONObject paramIn) {

//        UserDto userDto = new UserDto();
//        userDto.setUserId(paramIn.getString("userId"));
//        userDto.setTel(paramIn.getString("userTel"));
//        List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);

//        Assert.listOnlyOne(userDtos,"未找到用户信息");
//        List<UserAttrDto> userAttrDtos = userDtos.get(0).getUserAttrs();
//        String tmpUserId = getUserId(userAttrDtos);

        if(StringUtil.isEmpty(paramIn.getString("userId"))){
            return ResultVo.error("未找到业主信息");
        }
//        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
//        ownerAppUserDto.setUserId(paramIn.getString("userId"));
//        List<OwnerAppUserDto> ownerAppUserDtos = null;// ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
//
//        if(ownerAppUserDtos == null || ownerAppUserDtos.size()<1){
//            return ResultVo.error("未绑定业主");
//        }
//
//        RoomDto roomDto = new RoomDto();
//        roomDto.setCommunityId(ownerAppUserDtos.get(0).getCommunityId());
//        roomDto.setOwnerId(ownerAppUserDto.getOwnerId());
//        List<RoomDto> roomDtos = null;//roomInnerServiceSMOImpl.queryRoomsByOwner(roomDto);
        return ResultVo.createResponseEntity(new JSONArray());
    }

    private String getUserId(List<UserAttrDto> userAttrDtos) {

        for(UserAttrDto userAttrDto : userAttrDtos){
            if(UserAttrDto.SPEC_PROPERTY_USER_ID.equals(userAttrDto.getSpecCd())){
                return userAttrDto.getValue();
            }
        }

        return "";
    }
}
